package com.pinyoumei.app.activity.integral;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.activity.wallet.BackCardAdapter;
import com.pinyoumei.app.activity.wallet.BankCardListBean;
import com.pinyoumei.app.bean.GoodsTypeBean;
import com.pinyoumei.app.utils.SPUtils;

import java.util.ArrayList;
import java.util.List;

public class IntegralLeftMenuAdapter extends BaseAdapter {
    private Context context;
    private List<GoodsTypeBean.GoodsTypeDto> list = new ArrayList<>();
    public IntegralLeftMenuAdapter(Context context){
        this.context = context;
    }

    public void setData(List<GoodsTypeBean.GoodsTypeDto> list){
        this.list.clear();
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (viewHolder == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.integral_left_menu_item, parent, false);
            viewHolder = new ViewHolder(convertView);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        GoodsTypeBean.GoodsTypeDto dto = list.get(position);

        if(dto.isSelect()){
            viewHolder.leftMenuView.setVisibility(View.VISIBLE);
        }else{
            viewHolder.leftMenuView.setVisibility(View.GONE);
        }
        viewHolder.leftMenuTxt.setText(dto.getType_name());

        return convertView;
    }

    /**
     * ViewHolder,view缓存
     */
    static class ViewHolder {
        private View leftMenuView;
        private TextView leftMenuTxt;
        public ViewHolder(View view) {
            leftMenuView = view.findViewById(R.id.left_menu_view);
            leftMenuTxt = view.findViewById(R.id.left_menu_txt);
        }
    }

}
